﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using ThiagoSoftware.Dados;
using System.Web.Security;
using System.Data;

namespace GerTestes
{
    /// <summary>
    /// Summary description for Handler
    /// </summary>
    public class Handler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string sql = @"SELECT
                                   tu.FOTO
                            FROM   TB_USUARIOS tu
                            WHERE  tu.NOME = @USERNAME";
            DataAccess db = new DataAccess(sql);
            db.AddParam("@USERNAME", SqlDbType.VarChar, Membership.GetUser().UserName);
            db.AbrirConexao();
            SqlDataReader dr = db.ExecuteReader();
            dr.Read();
            context.Response.ContentType = "JPG";
            context.Response.BinaryWrite((byte[])dr["FOTO"]);
            dr.Close();
            db.FecharConexao();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}